home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / UNIX / NNTPFO~1.ZIP / NNTPFO~1.C
C/C++ Source or Header  |  1996-05-19  |  9KB  |  307 lines

  1. ok, here's the news forger.. two caveats on this one:
  2.  
  3. caveat #1: newer nntp servers insist on creating their own 
  4. "NNTP-Posting-Host:" header and will balk the post if you
  5. try to forge it.. this header, while not usually displayed
  6. by most readers, is distributed in a post and usually contains
  7. the correct pseudo-authenticated machine that the socket 
  8. connection was made from originally..
  9.  
  10. caveat #2: on one level, it seems that this is no better than sendmail
  11. or the forgepost no better than your run of the mill news poster - as
  12. it furthers people ability to ignore the mechanisms of things
  13. around them... further your mind and read the rfc's..  
  14.  
  15. take care, loki
  16. (argh thru_ : contribute to the Process)
  17.  
  18. -----news_forgery.h--------
  19.  
  20. /* written by Loki D. Quaeler (copyfree 1995) 
  21.    v1.0 */
  22.  
  23. /* #define DBUG */
  24.  
  25. #include <stdio.h>
  26. #include <strings.h>
  27. #include <errno.h>
  28. #include <signal.h>
  29. #include <unistd.h>
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <netinet/in.h>
  33. #include <netdb.h>
  34.  
  35. #define NEWSPORT..119
  36. #define.MAXLEN...256
  37. #define NNTP_INITIATE.."POST"
  38. #define NNTP_CLOSE.."QUIT"
  39. #define ORGANIZATION.."Organization:"
  40. #define FROM..."From:"
  41. #define SUBJECT..."Subject:"
  42. #define NEWSGROUPS.."Newsgroups:"
  43. #define DISTRIBUTION.."Distribution:"
  44. #define MSGID..."Message-ID:"
  45. #define NNTP_EODATA.."."
  46. #define GOOD_CONNECT_STR."ready"
  47. #define GOOD_POST_ACK.."240"
  48. #define BAD_NEWS.."no posting"
  49. #define GOOD_DISCONNECT.."205"
  50.  
  51. #define QUIT_EXEC.."quit"
  52.  
  53. #define DIST_DEFAULT.."world"
  54.  
  55. #define MAX_HOSTLEN..64
  56.  
  57. #define null(type)..(type) 0L
  58. #define NULL_STRING..""
  59.  
  60. #ifndef YES
  61. #define YES...1
  62. #define NO...0
  63. #endif
  64.  
  65. int s;...../* socket number */ 
  66. char buf[BUFSIZ+1];.../* global text data buffer     */
  67. char nntpHost[MAX_HOSTLEN];
  68. char newsgroups[MAXLEN];
  69. char pseudoSender[MAXLEN];
  70. char organization[MAXLEN];
  71. char subjectLine[MAXLEN];
  72. char distribution[MAXLEN];
  73. char messageID[MAXLEN];
  74. char *body;
  75.  
  76. -----news_forgery.c--------
  77. /* by Loki D. Quaeler - copyfree 1995 */
  78.  
  79. #include "news_forgery.h"
  80.  
  81. /*~~[ call_socket ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82.   Connect to port MAILPORT on host 'hostname', returning the socket
  83.   value.  Return -1 on any errors.
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  85. int call_socket(hostname)
  86.   char *hostname;
  87. {
  88. .struct sockaddr_in sa;
  89. .struct hostent *hp;
  90. .int a, sock;
  91.  
  92. #ifdef DBUG
  93.   printf("Entered call_socket, hostname = %s\n", hostname);
  94. #endif
  95.  
  96. .if ((hp=gethostbyname(hostname))==NULL)
  97. ..{ errno=ECONNREFUSED;
  98. ..  return(-1); }
  99. .bzero(&sa, sizeof(sa));
  100. .bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
  101. .sa.sin_family = hp->h_addrtype;
  102. .sa.sin_port = htons((u_short)NEWSPORT);
  103.  
  104. .if((sock=socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
  105. ..return(-1);
  106. .if(connect(sock, &sa, sizeof(sa)) < 0)
  107. ..{ close(sock);
  108. ..  return(-1); }
  109. #ifdef DBUG
  110.   printf("Exiting call_socket correctly, socket = %d\n", sock);
  111. #endif
  112. .return(sock);
  113. }
  114.  
  115. /*~~~[ readln ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116.   Read all characters from socket s until a newline.  Put resulting
  117.   string in buf, ignoring all after the BUFSIZ'th character.
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  119. int readln(buf)
  120.   char *buf;
  121. {
  122. .int to=0;
  123. .char c;
  124. .
  125. #ifdef DBUG
  126.   printf("Entering readln\n");
  127. #endif 
  128.  
  129. .do {
  130. ..if(read(s, &c, 1)<1) 
  131. ...return(0);
  132. ..if((c >= ' ') || (c <= 126))
  133. ...if(to<BUFSIZ-1) 
  134. ....buf[to++] = c;
  135. .} while (c != '\n');
  136.  
  137. .buf[to] = '\0';
  138.    
  139. #ifdef DBUG
  140.   printf("buf = %s", buf);
  141.   printf("Exiting readln correctly\n");
  142. #endif
  143.  
  144. .return(1);
  145. }
  146.  
  147. /*~~[ writeln ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148.   Send contents of buf to socket s.  Return 0 if the entire buf 
  149.   wasn't written.  Return 1 on a successful write.
  150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  151. int writeln(buf)
  152.   char *buf;
  153. {
  154. .int to=0;
  155.  
  156. #ifdef DBUG
  157.   printf("Entered writeln\n");
  158.   printf("buf = %s\n", buf);
  159. #endif
  160.  
  161. /*.buf[BUFSIZ] = '\0'; */
  162. .if( write(s, buf, strlen(buf)) < to )
  163. ..return(0);
  164.  
  165. #ifdef DBUG
  166.    printf("Exited writeln correctly.\n");
  167. #endif
  168.  
  169. .return(1);
  170. }
  171.  
  172. /*~~[ main ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173.   Yes, main.  amazing.
  174. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  175. main()
  176. {
  177. .char inputString[BUFSIZ],outputString[BUFSIZ];
  178. .char *dataBody;
  179. .int goodConnect = 0;
  180. .
  181. .printf("\n\nWelcome the news forgery Process...\n");
  182. .printf("\t-  After all data is entered, a confirmation entry will be\n\t\tasked for before the actual connection is made.\n\n");
  183. .
  184. .do {
  185. ..printf("~ Please enter NNTP server machine name\n\tor %s to exec program: ", QUIT_EXEC);
  186. ..gets(nntpHost);
  187. ..if (strcmp(nntpHost, QUIT_EXEC))
  188. ...{ goodConnect = contact_relay();
  189. ...  switch (goodConnect)
  190. ...  .{ case 0: printf("** Could not reach host\n"); break;
  191. ....  case 1: printf("** Host does not accept posting\n"); close(s); break;
  192. ....  default: close(s); break; } }
  193. ..else
  194. ...exit(0);
  195. .} while (goodConnect != 2);
  196.  
  197. .
  198.  
  199. .printf("~ Pseudonym (anything, any format): ");
  200. .gets(pseudoSender);
  201. .printf("~ Newsgroups to post to, multiple groups seperated\n\tby commas: ");
  202. .gets(newsgroups);
  203. .printf("~ Subject: ");
  204. .gets(subjectLine);
  205. .printf("~ Organization: ");
  206. .gets(organization);
  207. .printf("~ The distribution is defaulted to %s, enter a different one or\n\thit return: ", DIST_DEFAULT);
  208. .gets(distribution);
  209. .printf("~ Message-ID (ex: 23.23@ninth.circle.hell - *warning* some nntp\n\tservers do not like having this assigned for\n\tthem and will not correctly post because of\n\tit; hit return to skip this item) : ");
  210. .gets(messageID);
  211.  
  212. .printf("~ Enter the body below, enter ctrl-d on a blank line to end text entry.\n---------\n");
  213. .body = (char *)malloc(2);
  214. .sprintf(body,"\n");
  215. .while (gets(inputString) != NULL)
  216. ..{ if (! strcmp(inputString, NNTP_EODATA))
  217. ...sprintf(inputString,"%s.", NNTP_EODATA);
  218. ..  body = (char *)realloc(body,((strlen(body) + strlen(inputString) + 2) * sizeof(char)));
  219. ..  strcat(body,inputString);
  220. ..  strcat(body,"\n"); }
  221. .clearerr(stdin);
  222.  
  223. .printf("\n---------\n**This is the last chance to back out.\n\tContinue with the forgery Process (yes/no)? [no]:");
  224. .gets(inputString);
  225. .if (strcmp(inputString,"yes"))
  226. ..{ printf("Process was aborted.\n");
  227. ..  exit(0); }
  228. .
  229. .printf("-----\nContinuing...\n");
  230. .
  231. ./* build data body chunk */
  232.  
  233. .printf("  Building data body...\n");
  234.  
  235. .sprintf(inputString,"%s %s\n%s %s\n%s %s\n%s %s\n%s %s\n",FROM, pseudoSender,NEWSGROUPS, newsgroups,SUBJECT,subjectLine, ORGANIZATION, organization, DISTRIBUTION, ((strcmp(distribution,NULL_STRING)) ? distribution : DIST_DEFAULT ));
  236. .dataBody = (char*)malloc((strlen(inputString) + 1) * sizeof(char));.
  237. .strcat(dataBody,inputString);
  238.  
  239. .if (strcmp(messageID, NULL_STRING))
  240. ..{ sprintf(inputString,"%s <%s>\n", MSGID, messageID);
  241. ..  dataBody = (char*)realloc(dataBody,(strlen(dataBody) + strlen(inputString) + 1) * sizeof(char));.
  242. ..  strcat(dataBody,inputString); }
  243. .
  244. .dataBody = (char*)realloc(dataBody,(strlen(dataBody) + strlen(body) + 1) * sizeof(char));.
  245. .strcat(dataBody,body);
  246.  
  247. .printf(" Contacting nntp server...\n");
  248. .
  249. .contact_relay();
  250. .
  251. ../* speak that protocol slang */
  252.  
  253. .printf("  Exchanging protocol slang...\n");
  254.  
  255. .sprintf(buf,"%s\n", NNTP_INITIATE);
  256. .writeln(buf);
  257. .readln(outputString);
  258.  
  259. ../* monitor force feed of body into buf.... */
  260.  
  261. .printf("  Passing the body of mail...\n");
  262.  
  263. .writeln(dataBody);
  264. .
  265. .sprintf(buf,"\n%s\n", NNTP_EODATA);
  266. .writeln(buf);
  267. .readln(outputString);
  268.  
  269. .if (! strstr(outputString, GOOD_POST_ACK))
  270. ..printf("   Server didn't send good post acknowledgment. Post probably failed.\n");
  271.  
  272. .printf("  Closing connection...\n");
  273. .
  274. .sprintf(buf,"%s\n", NNTP_CLOSE);
  275. .writeln(buf);
  276. .readln(outputString);
  277. .if (strstr(outputString,GOOD_DISCONNECT))
  278. ..printf("Received good acknowldegment\n");
  279. .else
  280. ..printf("\t ~~ Unrecognized command at socket closure.\n");
  281.  
  282. .close(s);
  283. .
  284. .printf("------\nFinished... copy of sent message follows\n------\n%s\n------\n",dataBody);
  285. .
  286. .exit(0);
  287. }
  288.  
  289. int contact_relay()
  290. {  /* 0:host unreachable; 1:host connect but no posting allowed; 2: good host connect */
  291. .char serverSpew[BUFSIZ];
  292. .int i;
  293.  
  294. .if ((s=call_socket(nntpHost))==-1)
  295. ...return 0;
  296.  
  297. .do {
  298. ..readln(serverSpew);
  299. .} while (! strstr(serverSpew,GOOD_CONNECT_STR));
  300. .
  301. .if (strstr(serverSpew,BAD_NEWS))
  302. ..return 1;
  303. .else
  304. ..return 2;
  305. }
  306.  
  307.